package dongze.com.ckdj.adapter;

import android.content.IntentFilter;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.text.SimpleDateFormat;

import dongze.com.ckdj.R;
import dongze.com.ckdj.data.entity.response.GetNamePlateTodayResponse;
import dongze.com.ckdj.databinding.NamePlateTodayListItemBinding;
import dongze.com.ckdj.databinding.model.NamePlateTodayListItemModel;

/**
 * Created by fanqwz on 2017/8/18.
 */

public class NamePlateTodayAdapter extends BaseAdapter {
    private GetNamePlateTodayResponse data;

    public NamePlateTodayAdapter(GetNamePlateTodayResponse plateTodayResponse) {
        data = plateTodayResponse;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.getImgs().size();
    }

    @Override
    public Object getItem(int position) {
        return data == null ? null : data.getImgs().get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            NamePlateTodayListItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.name_plate_today_list_item, parent, false);
            NamePlateTodayListItemModel model = new NamePlateTodayListItemModel();
            binding.setModel(model);
            convertView = binding.getRoot();
            convertView.setTag(model);
        }

        NamePlateTodayListItemModel model = (NamePlateTodayListItemModel) convertView.getTag();
        model.vin.set(data.getImgs().get(position).getVin());
        model.img.set(data.getImgs().get(position).getImg());
        model.time.set(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
                convertView.getContext().getResources().getConfiguration().locale).format(data.getImgs().get(position).getuTime()));
        return convertView;
    }
}
